package com.ly.friend.controller.exam;

import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.R;
import com.ly.common.core.domain.TableDataInfo;
import com.ly.friend.domain.exam.dto.ExamQueryDTO;
import com.ly.friend.service.exam.IExamService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    private IExamService examService;

    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examDTO){
        return getTableDataInfo(examService.list(examDTO));
    }

    // semiLogin/list修改后经过缓存的
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examDTO){
       return examService.redisList(examDTO);
     }
    @GetMapping("/getFirstQuestion")
    public R<String> getFirstQuestion(Long examId){
        //代码逻辑: 获取竞赛中题目List 排在第一个的题目返回给前端
        //        redis =>list 类型是有序的(先从redis redis中没有查数据库)
        //        key: e:q:l    value: questionId
        //        排在第一个题目,返回给前端
        return R.ok(examService.getFirstQuestion(examId));
    }
    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long examId, Long questionId) {
        return R.ok(examService.preQuestion(examId, questionId));
    }

    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long examId, Long questionId) {
        return R.ok(examService.nextQuestion(examId, questionId));
    }
}
